<template>
  <div class="search-component">
    <div class="row status">
      <p class="label">处理状态</p>
      <template v-for="item in status" :key="item.value">
        <p
          @click="changeStatus(item.value)"
          class="name"
          :style="{
            background:
              searchModel.status === item.value
                ? 'var(--el-color-primary)'
                : '#fff',
            color: searchModel.status === item.value ? '#fff' : '#000',
          }"
        >
          {{ item.name }}
        </p>
      </template>
    </div>
    <div class="time row">
      <p class="label">提交时间</p>
      <div class="date-picker">
        <el-date-picker
          v-model="searchModel.date"
          type="daterange"
          range-separator="->"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          value-format="YYYY-MM-DD"
        />
      </div>

      <el-button type="primary" class="btn" :icon="Search" @click="search"
        >搜索</el-button
      >
      <el-button
        type="default"
        class="btn refresh"
        :icon="RefreshRight"
        @click="refresh"
        >重置</el-button
      >
    </div>
  </div>
</template>

<script setup>
import { Search, RefreshRight } from "@element-plus/icons-vue";
import { reactive } from "vue";

const emits = defineEmits(["search"]);

const searchModel = reactive({
  date: ["", ""],
  status: "",
});

const status = [
  {
    name: "全部",
    value: "",
  },
  {
    name: "未完成",
    value: 0,
  },
  {
    name: "已完成",
    value: 1,
  },
];

const changeStatus = (value) => {
  searchModel.status = value;
  emits("search", searchModel);
};

const search = () => {
  console.log(searchModel);
  emits("search", searchModel);
};

const refresh = () => {
  searchModel.date = ["", ""];
  searchModel.status = "";
  emits("search", searchModel);
};
</script>

<style lang="less" scoped>
.search-component {
  .row {
    display: flex;
    align-items: center;
  }
  .status {
    margin-bottom: 24px;
    .name {
      width: 60px;
      height: 28px;
      text-align: center;
      line-height: 28px;
      border-radius: 4px;
      margin-right: 12px;
      font-size: 14px;
      border-radius: 2px;
      cursor: pointer;
    }
  }
  .label {
    font-size: 14px;
    color: #333333;
    margin-right: 20px;
    font-weight: 600;
  }
  .time {
    .date-picker {
      margin-right: 34px;
    }
    .btn {
      width: 84px;
      height: 32px;
      border-radius: 2px;
    }
    .refresh {
      margin-left: 16px;
      background: #f1f1f1;
    }
  }
}
</style>
